import { aboutUser } from "../../store";

Page({
  data: {
    imId: "", //客服的抖音号
    userInfo: aboutUser.getUserInfo(),
    pageList: [{ title: "我的追剧", url: "/page/favorite/favorite" }],
  },

  onLoad() {
    this.setData({ imId: this.data.userInfo.imId });
    tt.setNavigationBarTitle({ title: this.data.userInfo.appTitle });
  },

  toPageFun(e) {
    const url = e.currentTarget.dataset.url;
    tt.navigateTo({ url });
  },

  getUserProfile() {
    tt.getUserProfile({
      force: true,
      success: (res) => {
        this.setData({
          userInfo: res.userInfo,
        });
      },
      fail(err) {
        console.log("tt.getUserProfile failed", err.errMsg);
        tt.showModal({
          title: "获取用户信息失败",
          content: err.errMsg,
          showCancel: false,
        });
      },
      complete() {},
    });
  },

  imCallback(e) {
    console.log("跳转IM客服成功", e.detail);
  },

  onimError(e) {
    console.log("拉起IM客服失败", e.detail);
    tt.showToast({
      title: `${e.detail.errMsg}`,
      success: (res) => {},
      fail: (res) => {},
    });
  },
});
